package utils

import "net/http"

type Result struct {
	Code int         `json:"code,omitempty"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

func NewResult() *Result {
	return &Result{}
}

func (r *Result) DefaultSuccess(data interface{}) Result {
	return Result{http.StatusOK, "请求成功", data}
}

func (r *Result) Success(msg string, data interface{}) Result {
	return Result{http.StatusOK, msg, data}
}

func (r *Result) Fail(code int, msg string) Result {
	return Result{code, msg, nil}
}

func (r *Result) DefaultFail(msg string) Result {
	return Result{http.StatusOK, msg, nil}
}
